---
# title: "Border Color"
title: "边框颜色"
# description: "Utilities for controlling the color of an element's borders."
description: "用于控制元素边框颜色的功能类。"
features:
  responsive: true
  customizable: true
  hover: true
  focus: false
---

import plugin from 'tailwindcss/lib/plugins/borderColor'
import { Variants } from '@/components/Variants'
import { Disabling } from '@/components/Disabling'
import { Heading } from '@/components/Heading'

export const classes = {
  plugin,
  preview: (css, { className }) => (
    <td className={`relative w-16 p-2 font-mono text-xs whitespace-pre ${className}`}>
      <div
        className="absolute inset-0 m-2 border"
        style={{
          borderColor: Array.isArray(css['border-color'])
            ? css['border-color'][0]
            : css['border-color'],
        }}
      />
    </td>
  ),
}

<!-- ## Usage -->
## 使用

<!-- Control the border color of an element using the `border-{color}` utilities. -->
使用 `border-{color}` 功能类控制元素的边框颜色。

```html rose
<template preview>
  <div class="max-w-xs w-full mx-auto">
    <input class="border border-red-500 bg-white text-gray-900 appearance-none block w-full rounded-md py-3 px-4 focus:outline-none" placeholder="Your email">
  </div>
</template>

<input class="border-2 **border-red-500** ...">
```

<!-- ### Changing opacity -->
### 改变不透明度值

<!-- Control the opacity of an element's border color using the `border-opacity-{amount}` utilities. -->
使用 `border-opacity-{amount}` 功能类控制元素边框颜色的不透明度值。

```html lightBlue
<template preview>
  <div class="grid grid-cols-2 gap-2 sm:grid-cols-5">
    <div class="h-16 flex-1 rounded border-4 border-light-blue-500 border-opacity-100 font-extrabold text-light-blue-600 flex justify-center items-center">100%</div>
    <div class="h-16 flex-1 rounded border-4 border-light-blue-500 border-opacity-75 font-extrabold text-light-blue-600 flex justify-center items-center">75%</div>
    <div class="h-16 flex-1 rounded border-4 border-light-blue-500 border-opacity-50 font-extrabold text-light-blue-600 flex justify-center items-center">50%</div>
    <div class="h-16 flex-1 rounded border-4 border-light-blue-500 border-opacity-25 font-extrabold text-light-blue-600 flex justify-center items-center">25%</div>
    <div class="h-16 flex-1 rounded border-4 border-light-blue-500 border-opacity-0 font-extrabold text-light-blue-600 flex justify-center items-center">0%</div>
  </div>
</template>

<div class="border-4 border-light-blue-500 **border-opacity-100** ..."></div>
<div class="border-4 border-light-blue-500 **border-opacity-75** ..."></div>
<div class="border-4 border-light-blue-500 **border-opacity-50** ..."></div>
<div class="border-4 border-light-blue-500 **border-opacity-25** ..."></div>
<div class="border-4 border-light-blue-500 **border-opacity-0** ..."></div>
```

<!-- Learn more in the [border opacity documentation](/docs/border-opacity). -->
在[边框不透明度文档](/docs/border-opacity)中了解更多。

<!-- ## Responsive -->
## 响应式

<!-- To control the border color of an element at a specific breakpoint, add a `{screen}:` prefix to any existing border color utility. For example, use `md:border-green-500` to apply the `border-green-500` utility at only medium screen sizes and above. -->
要在特定的断点处控制元素的边框颜色，请在任何现有的边框颜色功能类中添加 `{screen}:` 前缀。例如，使用 `md:border-green-500` 来应用 `border-green-500` 功能类在中等尺寸以上的屏幕上。

```html
<button class="border-blue-500 **md:border-green-500** ...">
  Button
</button>
```

<!-- For more information about Tailwind's responsive design features, check out the [Responsive Design](/docs/responsive-design) documentation. -->
关于 Tailwind 的响应式设计功能的更多信息，请查看[响应式设计](/docs/responsive-design)文档。

<!-- ## Hover -->
## 悬停
<!-- To control the border color of an element on hover, add the `hover:` prefix to any existing border color utility. For example, use `hover:border-blue-500` to apply the `border-blue-500` utility on hover. -->
要在悬停时控制元素的边框颜色，请在任何现有的边框颜色功能类中添加 `hover:` 前缀。例如，使用 `hover:border-blue-500` 在悬停时应用 `border-blue-500` 功能类。

```html purple
<template preview>
  <div class="flex items-center justify-center">
    <button class="border-2 border-purple-500 hover:border-gray-500 bg-transparent text-purple-700 hover:text-gray-700 py-3 px-4 font-semibold rounded-md">
      Button
    </button>
  </div>
</template>

<button class="border-2 border-purple-500 **hover:border-gray-500** ...">
  Button
</button>
```

<!-- Hover utilities can also be combined with responsive utilities by adding the responsive `{screen}:` prefix *before* the `hover:` prefix. -->
悬停功能类也可以通过在 `hover:` 前缀前添加响应的 `{screen}:` 前缀来与响应的功能类相结合使用。
```html
<button class="... md:border-blue-500 md:hover:border-blue-700 ...">Button</button>
```

<!-- ## Focus

To control the border color of an element on focus, add the `focus:` prefix to any existing border color utility. For example, use `focus:border-blue-500` to apply the `border-blue-500` utility on focus. -->
## 焦点

要控制焦点元素的边框颜色，请在任何现有的边框颜色功能类中添加 `focus:` 前缀。例如，使用 `focus:border-blue-500` 在焦点上应用 `border-blue-500` 功能类。

```html blue
<template preview>
  <div class="max-w-xs w-full mx-auto">
    <input class="border border-gray-300 bg-white text-gray-900 appearance-none block w-full rounded-md py-3 px-4 focus:border-blue-500 focus:outline-none" placeholder="Your email">
  </div>
</template>

<input class="border border-red-500 focus:border-blue-500 ...">
```

<!-- Focus utilities can also be combined with responsive utilities by adding the responsive `{screen}:` prefix *before* the `focus:` prefix. -->
通过在 `focus:` 前缀之前添加响应的 `{screen}:` 前缀，焦点功能类也可以与响应的功能类相结合使用。

```html
<input class="... md:border-gray-200 md:focus:border-white ...">
```

---

<!-- ## Customizing -->
## 自定义

<!-- ### Border Colors -->
### 边框颜色

<!-- By default Tailwind makes the entire [default color palette](/docs/customizing-colors#default-color-palette) available as border colors. -->
默认情况下，Tailwind 将整个[默认调色板](/docs/customizing-colors#default-color-palette)作为边框颜色。

<!-- You can [customize your color palette](/docs/colors#customizing) by editing the `theme.colors` section of your `tailwind.config.js` file, or customize just your border colors using the `theme.borderColor` section. -->
您可以通过编辑 `tailwind.config.js` 文件中的 `theme.colors` 部分来[定制您的调色板](/docs/colors#-2)，或者使用 `theme.borderColor` 部分来定制您的边框颜色。

```diff-js
  // tailwind.config.js
  module.exports = {
    theme: {
      borderColor: theme => ({
-       ...theme('colors'),
        DEFAULT: theme('colors.gray.300', 'currentColor'),
+       'primary': '#3490dc',
+       'secondary': '#ffed4a',
+       'danger': '#e3342f',
      })
    }
  }
```

<!-- ### Variants -->
### 变体

<Variants plugin="borderColor" />

<!-- ### Disabling -->
### 禁用

<Disabling plugin="borderColor" />
